home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Incognito / init / Init.c next >
Encoding:
C/C++ Source or Header  |  1994-02-20  |  3.1 KB  |  137 lines  |  [TEXT/MPS ]

  1. #include <Memory.h>
  2. #include <Resources.h>
  3. #include <GestaltValue.h>
  4. #include <Exceptions.h>
  5. #include <PLstringfuncs.h>
  6. #include <Folders.h>
  7. #include <TextUtils.h>
  8.  
  9. /*
  10.  
  11. asm patch.a
  12. asm install.a
  13. c nbpaction.c -b -opt full -w -d SystemSevenOrLater -sym full -mbg off
  14. c init.c -opt full -w -d SystemSevenOrLater -sym full -mbg off
  15. link install.a.o init.c.o patch.a.o nbpaction.c.o showinit.a.o -ra Main=resSysHeap,resLocked -m INITInstall Compass:Development:MPW:Libraries:Libraries:GestaltValue.o Compass:Development:MPW:Libraries:Libraries:Interface.o Compass:Development:MPW:Libraries:Libraries:Runtime.o -o 'Incog' -t INIT -c HEID -rt INIT -mf -Sym 'On '
  16. Rez ingoc.r -append -o incog
  17. rename Incog.sym 'Incog/INIT_0.sym'
  18. move Incog 'sextant:system folder:extensions:' -y
  19. move 'Incog/INIT_0.sym' 'sextant:system folder:extensions:' -y
  20. */
  21.  
  22. #define kSuccessIcon    -4064
  23. #define kFailureIcon    -4033
  24. #define kPrefsName        0
  25.  
  26. typedef struct NameLink
  27. {
  28.     Str32                originalName;
  29.     Str32                newString;
  30.     struct    NameLink    *next, *previous;
  31. } NameLink, *NameLinkPtr;
  32.  
  33. typedef struct OriginalLink
  34. {
  35.     Str32    originalName;
  36.     struct OriginalLink *next;
  37. } OriginalLink, *OriginalLinkPtr;
  38.  
  39. typedef struct
  40. {
  41.     NameLinkPtr        registeredNames;
  42.     OriginalLinkPtr    trappedNames;
  43. } MyGestaltRecord, *MyGestaltPtr;
  44.  
  45. pascal void ShowInit(short iconID, short moveX);
  46.  
  47. static void InsertItems(OriginalLinkPtr pb)
  48. {
  49.     Handle            temp;
  50.     Str32            rName;
  51.     short            rID;
  52.     OSType            rType;
  53.     OriginalLinkPtr newLink;
  54.     short            numTypes = Count1Resources('KILL');
  55.     
  56.     while (numTypes)
  57.     {
  58.         temp = Get1IndResource('KILL', numTypes);
  59.         if (temp)
  60.         {
  61.             GetResInfo(temp, &rID, &rType, rName);
  62.             ReleaseResource(temp);
  63.             newLink = (OriginalLinkPtr) NewPtrSysClear(sizeof(OriginalLink));
  64.             if (!newLink) return;
  65.             PLstrcpy(newLink->originalName, rName);
  66.             pb->next = newLink;
  67.             pb = pb->next;
  68.         }
  69.         numTypes--;
  70.     }
  71. }
  72.  
  73. static void InsertNames(OriginalLinkPtr pb)
  74. {
  75.     Str255    theString;
  76.     short    refNum;
  77.     FSSpec    theFile;
  78.     
  79.     FindFolder(-1, kPreferencesFolderType, true, &theFile.vRefNum, &theFile.parID);
  80.     GetIndString(theString, kPrefsName, 1);
  81.     if (!theString[0])
  82.     {
  83.         PLstrcpy(theFile.name, "\pIncognito Prefs");
  84.     }
  85.     PLstrcpy(theFile.name, theString);
  86.     refNum = FSpOpenResFile(&theFile, fsRdPerm);
  87.     if (refNum == -1)
  88.     {
  89.         FSpCreateResFile(&theFile, 'HEID', 'pref', 0);
  90.         refNum = FSpOpenResFile(&theFile, fsRdPerm);
  91.     }
  92.     if (refNum != -1)
  93.     {
  94.         InsertItems(pb);
  95.         CloseResFile(refNum);
  96.     };
  97. }
  98.  
  99. Boolean Initialize(void)
  100. {
  101.     OSErr            error;
  102.     MyGestaltPtr    pb;
  103.     NameLinkPtr        pc;
  104.     OriginalLinkPtr    pd;
  105.     
  106.     pb = (MyGestaltPtr)NewPtrSysClear(sizeof(MyGestaltRecord));
  107.     require(pb, mygestalt);
  108.     
  109.     pc = (NameLinkPtr)NewPtrSysClear(sizeof(NameLink));
  110.     require(pc, namelink);
  111. //    pc->originalName[0] = 32;
  112.     
  113.     pd = (OriginalLinkPtr)NewPtrSysClear(sizeof(OriginalLink));
  114.     require(pd, origlink);
  115. //    pd->originalName[0] = 32;
  116.     
  117.     pb->registeredNames = pc;
  118.     pb->trappedNames = pd;
  119.     
  120.     InsertNames(pd);
  121.     
  122.     error = NewGestaltValue('HEID', (long) pb);
  123.     nrequire(error, newgestalt);
  124.     
  125.     ShowInit(kSuccessIcon, 40);
  126.     return noErr;
  127.     
  128. newgestalt:
  129.     DisposePtr((Ptr) pd);
  130. origlink:
  131.     DisposePtr((Ptr) pc);
  132. namelink:
  133.     DisposePtr((Ptr) pb);
  134. mygestalt:
  135.     ShowInit(kFailureIcon, 40);
  136.     return error;
  137. }